// Fill out your copyright notice in the Description page of Project Settings.
PRAGMA_DISABLE_OPTIMIZATION

#include "InteractionParticipantComponent.h"
#include "AnimSampleGameInstance.h"

// Sets default values for this component's properties
UInteractionParticipantComponent::UInteractionParticipantComponent()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = true;

	// ...
}


// Called when the game starts
void UInteractionParticipantComponent::BeginPlay()
{
	Super::BeginPlay();

	UAnimSampleGameInstance* GameInstance = (UAnimSampleGameInstance*)GetWorld()->GetGameInstance();
	if(GameInstance != nullptr)
	{
		GameInstance->RegisterInteractionScriptFunctionByName(this, "NotifyParticipantStartScript", StartScriptFunctionName);
		GameInstance->RegisterInteractionScriptFunctionByName(this, "NotifyParticipantStopScript", StopScriptFunctionName);
	}
}


// Called every frame
void UInteractionParticipantComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}

void UInteractionParticipantComponent::ServerParticipantStart(AActor* Interactor, AActor* Participant)
{
	if(NotifyParticipantStartScript.IsBound())
	{
		NotifyParticipantStartScript.Execute(Interactor, Participant);
	}	
}

void UInteractionParticipantComponent::ServerParticipantStop(AActor* Interactor, AActor* Participant)
{
	if(NotifyParticipantStopScript.IsBound())
	{
		NotifyParticipantStopScript.Execute(Interactor, Participant);
	}
}

